home *** CD-ROM | disk | FTP | other *** search
/ Directorty Opus 5 - Magellan 2 / Opus 5 - Magellan 2.iso / Extras / DOpus511 / dopus_pch.lha / ARexx.lha / Arexx / PBar.dopus5 < prev    next >
Text File  |  1995-06-09  |  5KB  |  143 lines

  1. /* Progress-Bar v1.02 [13-May-1995] for Directory Opus 5.
  2.    By Leo Davidson ("Nudel", P0T-NOoDLE/Gods'Gift Utilities)
  3.  
  4.    This ARexx script will add a progress bar (like when deleting files)
  5.    to external commands which are run on all the selected entries in a
  6.    lister.
  7.  
  8. Call as:
  9. ------------------------------------------------------------------------------
  10. ARexx    PBar.dopus5 {Qp} "<1>" "<2>"
  11. ------------------------------------------------------------------------------
  12. Where <1> is the AmigaDOS command to be run for each file.
  13.  Insert "!!f!!" (without quotes) where you would like the full path to the
  14.  selected file (you can insert it more than once, if you require).
  15. <2> is the progress window title.
  16.  
  17. If <1> or <2> have any spaces in them, "put quotes around them".
  18.  
  19. The "Do All Files" switch MUST be turned *_OFF_*!!!
  20.  
  21. e.g.
  22. ------------------------------------------------------------------------------
  23. ARexx    DOpus5:ARexx/PBar.dopus5 {Qp} "C:PackIt !!f!! CRUNCH" "Packing files:"
  24. ------------------------------------------------------------------------------
  25.  
  26. Note: The command you use must be able to handle "filenames with quotes".
  27.  
  28. TO DO:
  29. ------
  30. - Make it rescan all selected entries.
  31.   (Short of making it rescan the entire dir, which you can do as a switch
  32.   within DOpus, I don't think there is a way to emulate "Reload each file"
  33.   via an ARexx script, at least in the current version of DOpus5.)
  34. - Perhaps propper support for all the {} type codes, not just {f}.
  35. - ONLY DIRS and ONLY FILES options.
  36.   (If you don't want it to act on files or on dirs, simply don't select them!)
  37. - Take a filetype-ID so that only files matching it are acted on.
  38.   (this would actually be a pain to impliment - I'm not about to).
  39. */
  40.  
  41. /*-- Setup ------------------------------------------------------------------*/
  42. /* You should edit the SepBar below to look right with your output-window
  43.    setup (use the script and you'll see what it does). */
  44. SepBar = "-----------------------------------------------------------------------------------"
  45.  
  46. options results
  47. options FAILAT 99
  48. signal on syntax;signal on ioerr        /* Error trapping */
  49.  
  50. /*- Parse the command-line --------------------------------------------------*/
  51. CmdLine = ARG(1)
  52. DOpusPort = GetCmdWord()
  53. UserCommand = GetCmdWord()
  54. UserTitle = GetCmdWord()
  55.  
  56. If DOpusPort~="" THEN Address value DOpusPort
  57. ELSE Do
  58.     Say "Not correctly called from Directory Opus 5!"
  59.     Say "Load this ARexx script into editor for more info."
  60.     EXIT
  61.     END
  62.  
  63. If UserTitle="" Then UserTitle = "Doing all files..."
  64.  
  65. lister query source                /* Get lister and set busy */
  66. IF RC ~= 0 Then Do
  67.     dopus request '"You must have a SOURCE lister!" OK'
  68.     EXIT
  69.     End
  70. Lister_Handle = RESULT
  71. lister set Lister_Handle busy 1
  72.  
  73. lister query Lister_Handle numselentries    /* Get info about selected */
  74. Lister_NumSelEnt = RESULT            /* entries & path to them */
  75. lister query Lister_Handle path
  76. Lister_Path = Strip(RESULT,"B",'"')
  77.  
  78. If Lister_NumSelEnt = "RESULT" | Lister_Path = "RESULT" Then Do
  79.     lister set Lister_Handle busy 0
  80.     EXIT
  81.     END
  82.  
  83. /*-- The Progress Bar ---------------------------------------------------------
  84. A progress bar will display how many of the selected files have been done.
  85. This means the max-number argument is Lister_NumSelEnt.
  86. For each selected entry, the "Do i..." loop updates the progress bar,
  87. builds and executes the user-defined command, and then de-selects.
  88. -----------------------------------------------------------------------------*/
  89. lister set Lister_Handle progress Lister_NumSelEnt UserTitle
  90.  
  91. Do i=1 to Lister_NumSelEnt
  92.     lister query Lister_Handle firstsel
  93.     Temp_Name = RESULT
  94.     lister select Lister_Handle Temp_Name 0
  95.     Temp_Name = Strip(Temp_Name,"B",'"')
  96.     lister set Lister_Handle progress name Temp_Name
  97.     lister set Lister_Handle progress count i
  98.     lister query Lister_Handle abort
  99.     IF RESULT=1 THEN BREAK        /* If they aborted, break the loop */
  100.  
  101.     Temp_Name = '"'||Lister_Path||Temp_Name||'"'
  102.     Temp_Exec = Upper(UserCommand)
  103.     Do While Index(Temp_Exec,"!!F!!") ~= 0
  104.         Temp_Pos = Index(Temp_Exec,"!!F!!")
  105.         Temp_Exec = DelStr(Temp_Exec,Temp_Pos,"5")
  106.         Temp_Exec = Insert(Temp_Name,Temp_Exec,Temp_Pos-1)
  107.         END
  108.     Address Command Temp_Exec
  109.     Say SepBar
  110.     END
  111.  
  112. /*-- Restore the Lister for normal use --------------------------------------*/
  113. syntax:;ioerr:                /* In case of error, jump here */
  114. lister clear Lister_Handle progress
  115. lister refresh Lister_Handle
  116. lister set Lister_Handle busy 0
  117.  
  118. EXIT
  119.  
  120.  
  121. /*- Function for Command-Line parsing -----------------------------------------
  122.  ARexx's "PARSE ARG" is rank. It isn't very good at handling arguments with
  123.  "quotes" (especially when the quotes are optional), and inserts spaces
  124.  where you don't want them sometimes. I don't have the docs to RexxDosSupport,
  125.  so I wrote my own function which extracts the next argument from the string
  126.  "CmdLine", respecting quotes, and not adding extra spaces at either side.
  127. -----------------------------------------------------------------------------*/
  128. GetCmdWord:
  129.     Temp_CmdWord = Word(CmdLine,1)
  130.     CmdLine = DelWord(CmdLine,1,1)
  131.  
  132.     If Left(Temp_CmdWord,1) = '"' Then Do Forever
  133.         If Right(Temp_CmdWord,1) = '"' Then Break
  134.         If Words(CmdLine) = "0" Then Call BadCmd_Quotes
  135.         Temp_CmdWord = Temp_CmdWord||" "||Word(CmdLine,1)
  136.         CmdLine = DelWord(CmdLine,1,1)
  137.         End
  138.     Return Strip(Temp_CmdWord,"B",'"')
  139.  
  140. BadCmd_Quotes:
  141.     dopus request '"PBar.dopus5: Bad Command Line.' || X2C(0A) || 'Unclosed quotes in string." OK'
  142.     EXIT
  143.